<!--
 * @Description: 工程交底信息
 * @Author: yijiaxin
 * @Date: 2021-10-21 15:26:20
-->
<template>
    <el-form ref="form" class="form" :model="projectForm" :disabled="disabled" label-width="120px" label-position="right" hide-required-asterisk>
        <el-form-item v-for="item in form" :key="item.key" :label="item.label" :prop="item.required ? item.key : ''" :rules="{ required: true, message: `${item.label}不能为空`}">
            <span v-if="item.required" slot="label" style="color: #ff0000" >{{item.label}}</span>
            <div v-if="item.type === 'input'">
                <el-input v-model="formData[item.key]" :style="item.style" placeholder="请输入">
                    <template v-if="item.append" slot="append">{{item.append}}</template>
                    <template v-if="item.prepend" slot="prepend">{{item.prepend}}</template>
                </el-input>
            </div>
            <div v-if="item.type === 'select'">
                <el-select v-model="formData[item.key]" :style="item.style" :multiple="item.multiple" placeholder="请选择">
                    <el-option v-for="option in item.options" :key="option.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
            </div>
            <div v-if="item.type === 'radio'">
                <el-radio-group v-model="formData[item.key]">
                    <el-radio v-for="radio in item.radios" :key="radio.text" :label="radio.label">{{ radio.text }}</el-radio>
                </el-radio-group>
                <el-select v-if="item.selectKey" v-model="formData[item.selectKey]" :style="item.style" placeholder="请选择">
                    <el-option v-for="option in item.options" :key="option.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
            </div>
            <div v-if="item.type === 'cascader'">
                <el-cascader v-model="formData[item.key]" :style="item.style" :options="item.options" filterable></el-cascader>
            </div>
            <div v-if="item.type ==='date'">
                <el-date-picker 
                    v-model="formData[item.key]"
                    :style="item.style" 
                    :type="item.dateType" 
                    :range-separator="item.range-separator || '至'" 
                    :start-placeholder="item.startPlaceholder || '开始日期'" 
                    :end-placeholder="item.endPlaceholder || '结束日期'" 
                    :placeholder="item.placeholder || '选择时间'"
                    :value-format="item.valueFormat || 'yyyy-MM-dd'">
                </el-date-picker>
            </div>
        </el-form-item>
    </el-form>
</template>

<script>
    import { getDicsType } from "@/api/common.js";
    // import { getDicType, getListByTypeId, getDicsType, getStationByCompanyId } from "@/api/common.js";
    import { queryAllByCompanyId, getOrganizationBytypes } from '@/api/internetSales/chanceManagement.js'
    import treeData from '@/views/platform/ICPS/basicConfig/address.js';
    import { get_simple_user_listBycompanyId } from '@/api/GHnumber/contract.js'
    export default {
        data() {
            return {
                enginnerrNatureIdList:[], // 工程性质下拉列表数据
                form:[
                    {
                        key: 'discloseType',
                        label: '交底类型',
                        required: true,
                        type: 'select',
                        options: [
                            {value: 1, label: '委托交底'},
                            {value: 2, label: '合同交底'}
                        ]

                    },
                    {
                        key: 'enginnerrName',
                        label: '工程名称',
                        required: true,
                        type: 'input',
                    },
                    {
                        key: 'enginnerrNatureId',
                        label: '工程性质',
                        required: true,
                        type: 'select',
                        options: async ()=> {
                            const res = await getDicsType({ codes: "EngineeringNature,contractType,MATname,castingType,shutdownLogo, placeDon, recordFixedPostition, market" });
                            if(res && res.code === 1001) 
                            return res.data.EngineeringNature.items.forEach(item=>({value: item.id, label: item.itemName}));
                        }
                    },
                    {
                        key: 'enginnerrAddress',
                        label: '工程地址',
                        required: true,
                        type: 'input',
                    },
                    {
                        key: 'administrativeDistrictsId0',
                        label: '行政区',
                        required: true,
                        type: 'cascader',
                        options: () => treeData.forEach((v) => {
                                            v.children.forEach((res) => {
                                                res.children.forEach((res2) => {
                                                    delete res2.children
                                                })
                                            })
                                        })
                    },
                    {
                        key: 'poolFlag',
                        label: '联营标识',
                        required: true,
                        type: 'select',
                        options:[
                            {value: 0, label: '否'},
                            {value: 1, label: '是'},
                        ]
                    },
                    {
                        key: 'sidesFlag',
                        label: '内外标识',
                        required: true,
                        type: 'radio',
                        radios:[
                            { label: 1, text: '内'},
                            { label: 2, text: '外'},
                        ],
                        selectKey: 'sidesFlagType',
                        options: [
                            {value: 1, label: '央企'},
                            {value: 2, label: '地方企业'},
                            {value: 3, label: '其他'},
                        ]
                    },
                    {
                        key: 'coordinateName',
                        label: '协调主体',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'collaborationType',
                        label: '往来协作',
                        required: true,
                        type: 'select',
                        options: [
                            {value: 1, label: '非往来协作'},
                            {value: 2, label: '外协'},
                            {value: 3, label: '协外'},
                        ]
                    },
                    {
                        key: 'collaborationUnit',
                        label: '往来协作公司',
                        required: true,
                        type: 'select',
                        options: async ()=>{
                            const res = await getOrganizationBytypes({typeId:'19da56b9e85648059e3cf1e7da497da4,b8f9367217ab43f8924cd6c08a9ba300'});
                            if(res && res.code === 1001) {
                                return res.data.EngineeringNature.items.forEach(item=>({value: item.id, label: item.name}));
                            }
                        }
                    },
                    {
                        key: 'enginnerrLiveDescription',
                        label: '工程现场特性描述',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'constructionCompany',
                        label: '施工单位',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'contractCompany',
                        label: '委托单位',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'entrustBeginTImeEntrustEndTime',
                        label: '委托期',
                        required: true,
                        type: 'date',
                        dateType: 'daterange',
                    },
                    {
                        key: 'entrusNumber',
                        label: '委托量',
                        required: true,
                        type: 'input',
                        append: '方'
                    },
                    {
                        key: 'contractNo',
                        label: '合同号',
                        required: true,
                        type: 'input',
                    },
                    {
                        key: 'constructionStartDateConstructionEndDate',
                        label: '施工工期',
                        required: true,
                        type: 'date',
                        dateType: 'daterange',
                    },
                    {
                        key: 'qiRecord',
                        label: '质监备案号',
                        required: true,
                        type: 'input',
                    },
                    {
                        key: 'qiRecord',
                        label: '质监备案号',
                        required: true,
                        type: 'input',
                    },
                    {
                        key: 'businesNameId',
                        label: '合同单位',
                        required: true,
                        type: 'select',
                        options: async () => {
                            const res = queryAllByCompanyId();
                            if (res.code === 1001) {
                                return res.data.forEach(item=>({value: item.id, label: item.name}));
                            }
                        }
                    },
                    {
                        key: 'contractSumNumber',
                        label: '合同总量',
                        required: true,
                        type: 'input',
                    },
                    {
                        key: 'contractPriceOfFax',
                        label: '合同含税总价',
                        required: true,
                        type: 'input',
                    },
                    {
                        key: 'effectiveDate',
                        label: '合同生效日期',
                        required: true,
                        type: 'date',
                        dateType: 'month',
                        valueFormat: 'yyyy-MM'
                    },
                    {
                        key: 'firstIndateEndIndate',
                        label: '合同有效期',
                        required: true,
                        type: 'date',
                        dateType: 'monthrange',
                        valueFormat: 'yyyy-MM'
                    },
                    {
                        key: 'modelOfContract',
                        label: '合同模式',
                        required: true,
                        type: 'select',
                        options: [
                            { value: 1, label: '包干' },
                            { value: 2, label: '代工' },
                            { value: 3, label: '其他' },
                        ]
                    },
                    {
                        key: 'budgetPersonId',
                        label: '预算员',
                        required: true,
                        type: 'select',
                        options: async ()=> {
                            const res = await get_simple_user_listBycompanyId({
                                roleId: '48d84b503be7484ca1b5c2eade1ff004',
                                orgznizationId: this.$route.query.companyId
                            });
                            if(res && res.code === 1001) 
                            return res.data.forEach(item=>({value: item.id, label: item.name}));
                        }
                    },
                    {
                        key: 'sallerId',
                        label: '销售员',
                        required: true,
                        type: 'select',
                        options: async ()=> {
                            const res = await get_simple_user_listBycompanyId({
                                roleId: '12b2f6ff304148fd89141e9faa9afb96',
                                orgznizationId: this.$route.query.companyId
                            });
                            if(res && res.code === 1001) 
                            return res.data.forEach(item=>({value: item.id, label: item.name}));
                        }
                    },
                    {
                        key: 'placeTypeId',
                        label: '销售员处别',
                        required: true,
                        type: 'select',
                        options: async ()=> {
                            const res = await getDicsType({ codes: "EngineeringNature,contractType,MATname,castingType,shutdownLogo, placeDon, recordFixedPostition, market" });
                            if(res && res.code === 1001) 
                            return res.data.placeDon.items.forEach(item=>({value: item.id, label: item.itemName}));
                        }
                    },
                    {
                        key: 'firstLeader',
                        label: '甲方项目负责人及权限',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'ourCompanyCheckPersonId',
                        label: '我司合同签字人',
                        required: true,
                        type: 'select',
                        options: async ()=> {
                            const res = get_simple_user_listBycompanyId({
                                            roleId: '7605679267385344',
                                            orgznizationId: this.$route.query.companyId
                                        })
                            if(res && res.code === 1001) {
                                return res.data.forEach(item=>({value: item.id, label: item.itemName}));
                            }
                        }
                    },
                    {
                        key: 'richAmount',
                        label: '甲方有权对量',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'firstPartySigner',
                        label: '甲方小票签收人',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'firstPartyMailbox',
                        label: '甲方指定邮箱',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'secondPartyMailbox',
                        label: '乙方指定邮箱',
                        required: true,
                        type: 'input'
                    },
                    {
                        key: 'qualityAgreementIds',
                        label: '质量约定',
                        required: true,
                        type: 'select',
                        options: async ()=> {
                            const res = get_simple_user_listBycompanyId({
                                            roleId: '7605679267385344',
                                            orgznizationId: this.$route.query.companyId
                                        })
                            if(res && res.code === 1001) {
                                return res.data.forEach(item=>({value: item.id, label: item.itemName}));
                            }
                        }
                    },
                ],
                formData: {}
            };
        },
        props: {
            config: {
                type: Object,
                default: () => {},
            },
            // 控制dialog显示
            visible: {
                type: Boolean,
            },
        },
        methods: {
            // 获取下拉列表数据
            getDicType() {
                getDicsType({ codes: "EngineeringNature,contractType,MATname,castingType,shutdownLogo, placeDon, recordFixedPostition, market" }).then((res) => {
                if (res.code === 1001) {
                    this.enginnerrNatureIdList = res.data.EngineeringNature.items.forEach(item=>({value: item.id, label: item.itemName}));
                }
                });
            },
            onOpen() {},
            onClose() {
                this.$emit('update:visible', false);
            },
            onConfirm() {
                this.$emit('updated', false);
                this.$emit('update:visible', false);
            },

        },
    };
</script>

<style lang="scss" scoped>
.form {
    .el-form-item {
        width: 50%;
    }
}
</style>

